package com.hnevn.newslist;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class MyAdapter extends BaseAdapter {
    private static final String TAG = "MyAdapter";
    MainActivity contenxt;
    List<NewBean.ResultBean.DataBean> list;
    public MyAdapter(MainActivity contenxt, List<NewBean.ResultBean.DataBean> list) {
        this.contenxt = contenxt;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = View.inflate(contenxt,R.layout.item_layout,null);
        }
//        绑定控件
        WebView mIvImage = convertView.findViewById(R.id.iv_imag);
        TextView mTvTitle = convertView.findViewById(R.id.tv_title);
        TextView mTvTime = convertView.findViewById(R.id.tv_time);
//        将数据渲染上去
        mTvTitle.setText(list.get(position).getTitle());
        mTvTime.setText(list.get(position).getDate());
        mIvImage.loadUrl(list.get(position).getThumbnail_pic_s());
        return convertView;
    }
}
